import _update from 'immutability-helper';
import {genUpdater,getUpdaterKeys,getFixLack} from './genUpdater';
import get from 'lodash/get';

export const updateNoFixPath=function(target,updater){
    return _update(target,genUpdater(updater));
};
export const updateRaw=_update;
export const update=function(target,updater){
    const keys=getUpdaterKeys(updater);
    let key;
    let _target=target;
    for(let i=0,il=keys.length;i<il;i++){
        key=keys[i];
        if(typeof get(target,key)==='undefined'){
            _target=_update(_target,getFixLack(key));
        }
    }
    return _update(_target,genUpdater(updater));
};

export default update;